package com.adaptiveAgingAdmin.service.impl;

import com.adaptiveAgingAdmin.domain.Admin;
import com.adaptiveAgingAdmin.mapper.AdminMapper;
import com.adaptiveAgingAdmin.service.AdminService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.authentication.BadCredentialsException;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

@Service
public class AdminServiceImpl extends ServiceImpl<AdminMapper, Admin> implements AdminService {

    @Autowired
    private AdminMapper adminMapper;


    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        Admin admin = adminMapper.getByUsername(username);
        if(ObjectUtils.isEmpty(admin)){
            throw new BadCredentialsException("用户名不存在!");
        }
        return admin;
    }
}
